package study;

/**
 * 表示猜拳游戏中的手势
 */
public class Hand {

    /**
     * 表示石头
     */
    public final static int HANDVALUE_GUU = 0;

    /**
     * 表示剪刀
     */
    public final static int HANDVALUE_CHO = 1;

    /**
     * 表示布
     */
    public final static int HANDVALUE_PAA = 2;

    /**
     * 表示三种手势的实例
     */
    public static final Hand[] HAND = {
            new Hand(HANDVALUE_GUU),
            new Hand(HANDVALUE_CHO),
            new Hand(HANDVALUE_PAA)
    };

    /**
     * 手势所对应的字符串
     */
    private static final String[] NAME = {
            "石头", "剪刀", "布"
    };

    private int handValue;
    private Hand(int handValue) {
        this.handValue = handValue;
    }

    /**
     * Get hand hand.
     *
     * @param handValue the hand value
     * @return the hand
     */
    public static Hand getHand(int handValue){
        return HAND[handValue];
    }

    /**
     * 是否大于
     *
     * @param hand the hand
     * @return boolean
     */
    public boolean isStrongThan(Hand hand){
        return this.fight(hand) == 1;
    }

    /**
     * 是否小于
     *
     * @param hand the hand
     * @return the boolean
     */
    public boolean isWeakThan(Hand hand) {
        return this.fight(hand) == -1;
    }

    /**
     * 是否等于
     *
     * @param hand the hand
     * @return the boolean
     */
    public boolean isEqualThan(Hand hand) {
        return this.fight(hand) == 0;
    }

    private int fight(Hand hand){
        if(this.handValue == hand.handValue){
            return 0;
        } else if((this.handValue + 1) % 3 == hand.handValue){
            return 1;
        } else {
            return -1;
        }
    }
}
